﻿// JScript File

function onDrop(sender, e)
{
    var container = e.get_container();
    var item = e.get_droppedItem();
    var position = e.get_position();
    var column = parseInt(container.getAttribute("columnid"));
    var widget = parseInt(item.getAttribute("widgetid"));
    var row = position;

    try
    {
       EWorking.Portal.UserPortalSvc.SaveUserPortal(PortalLayoutID, widget, column, row);
    }
    catch(e)
    {
    }
}
function UpdateUI(dock, e)
{
    var dockZone = dock.get_dockZone();
    var dockZoneUniqueName = dockZone.get_uniqueName();
    var uniqueName = dock.get_uniqueName();
    var columnID = dockZoneUniqueName.substring(dockZoneUniqueName.lastIndexOf("_") + 1);
    var widgetID = uniqueName.substring(uniqueName.lastIndexOf("_") + 1);
    var rowID = dock.get_index();
    try
    {
       EWorking.Portal.UserPortalSvc.SaveUserPortal(PortalLayoutID, widgetID, columnID, rowID);
    }
    catch(e)
    {
    }
}
function WidgetCommand(dock, e)
{
    e.set_cancel(true);
    if (e.command.get_name().toUpperCase() == "CLOSE")
    {
        var uniqueName = dock.get_uniqueName();
        var widgetID = uniqueName.substring(uniqueName.lastIndexOf("_") + 1);
        RemoveWidget(widgetID);
    }
}

function __RemoveWidget(widget)
{
    var widgetid = parseInt(widget.getAttribute("widgetid"));
    if (confirm("Bạn có chắc muốn gỡ bỏ tiện ích này?"))
    {
        try
        {
            EWorking.Portal.UserPortalSvc.RemoveWidget(PortalLayoutID, widgetid);
            var removedWidget = document.getElementById("widget_" + widgetid);
            if (removedWidget)
            {
                removedWidget.style.visibility = "hidden";
                removedWidget.style.display = "none";
                widget.parent.removeChild(removedWidget);
            }
        }
        catch(e)
        {
        }
    }
    return false;
}